package com.enjoyor.soa.traffic.core.efoms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.efoms.domain.FaultHourCollect;
import com.enjoyor.soa.traffic.core.efoms.mapper.IFaultHourCollectMapper;
import com.enjoyor.soa.traffic.core.efoms.service.IFaultHourCollectService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;

@Service
@Transactional
public class FaultHourCollectService implements IFaultHourCollectService {

    @Autowired
    private IFaultHourCollectMapper faultHourCollectMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Override
    public FaultHourCollect selectFaultHourCollectById(String faulHourId){
        return faultHourCollectMapper.selectById(faulHourId);
    }
    
    @Override
	public List<FaultHourCollect> selectFaultHourCollectList(String devCategoryCode,
			String devTypeCode, String collectStartTime, String collectEndTime) {
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("devCategoryCode", devCategoryCode);
	    	paramT.put("devTypeCode", devTypeCode);
	    	paramT.put("collectStartTime", collectStartTime);
	    	paramT.put("collectEndTime", collectEndTime);
	    	return faultHourCollectMapper.selectFaultHourCollectList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public List<FaultHourCollect> selectFaultRealCollectList(String devCategoryCode, String devTypeCode){
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("devCategoryCode", devCategoryCode);
	    	paramT.put("devTypeCode", devTypeCode);
	    	return faultHourCollectMapper.selectFaultRealCollectList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String insertFaultHourCollect(FaultHourCollect faultHourCollect, String personName){
    	try {
	    	// 默认操作记录信息
	        String faulHourId = "FH" + TimeHelper.getUniqueString();
	        faultHourCollect.setFaulHourId(faulHourId);
	        faultHourCollect.setCollectTime(TimeHelper.dateToLongString());
	        faultHourCollectMapper.insert(faultHourCollect);
	    	
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
	                String.format("添加异常分时统计编号:{%s} 操作成功!", new Object[] { faulHourId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return faulHourId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }

    @Override
    public String updateFaultHourCollect(FaultHourCollect faultHourCollect, String personName){
    	try {
	    	String faulHourId = faultHourCollect.getFaulHourId();
	    	//faultHourCollect.setCollectTime(TimeHelper.dateToLongString());
	        faultHourCollectMapper.updateByIdSelective(faultHourCollect);
	        pubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改异常分时统计编号:{%s} 操作成功!", new Object[] { faulHourId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return faulHourId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }

    @Override
    public String deleteFaultHourCollect(String faulHourId, String personName){
    	try {
    		faultHourCollectMapper.deleteById(faulHourId);
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
	                String.format("删除异常分时统计编号:{%s} 操作成功!", new Object[] { faulHourId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return faulHourId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
}
